#include <fstream>
#include <string>
#include <iostream>
#include <sstream>

using namespace std;

struct Scores
{
	char name[4];
	int score;
};

void loadscores(Scores scores[])
{
	string tempscore;
	string tempname;

	ifstream HighScores;
	ifstream HighNames;

	HighScores.open("Scores.dat");
	HighNames.open("Names.dat");

	for(int i = 0; i < 9; i++)
	{
		if(!HighScores.eof() || !HighNames.eof())
		{
			getline(HighScores, tempscore);
			scores[i].score = atoi(tempscore.c_str());
			getline(HighNames, tempname);
			strcpy_s(scores[i].name,tempname.c_str());
			std::cout << i <<":" <<"Name:"<< scores[i].name << ":" << "Score" << scores[i].score;
			std::cout << '\n';
		}
	}
}
void savescores(Scores scores[])
{
	ofstream HighScores;
	ofstream HighNames;

	HighScores.open("Scores.dat");
	HighNames.open("Names.dat");

	for(int i = 0; i < 9; i++)
	{
		HighScores << scores[i].score << "\n";
		HighNames << scores[i].name << "\n";
	}
}

int checkplacement(Player &player, Scores scores[])
{
	for(int i = 0; i < 10; i++)
	{
		if(player.score >= scores[i].score)
			return i;
	}
	return 20;
}
void movedownplayers(Scores scores[],int newscore, int place, char newname[], Player &player)
{
	for(int i = 8; i > 0; i--)
	{
		if(player.score > scores[i].score)
		{
			for(int c = 0; c < 4; c++)
			{
				scores[i].name[c] = scores[i-1].name[c];
			}
			scores[i].score = scores[i-1].score;
		}
	}
	for(int y = 0; y < 3; y++)
	{
		scores[place].name[y] = newname[y];
	}
	scores[place].score = newscore;
	return;
}

void drawscores(Scores scores[], ALLEGRO_FONT *font)
{
	al_draw_text(font,al_map_rgb(200,100,55),10,20,0,"Rank");
	al_draw_text(font,al_map_rgb(200,100,55),410,20,0,"Name");
	al_draw_text(font,al_map_rgb(200,100,55),820,20,0,"Score");

	for(int i = 0; i < 8;i++)
	{
		al_draw_textf(font,al_map_rgb(200,100,55),30,50+30*i,ALLEGRO_ALIGN_CENTER,"%i",i+1);
	}
	for(int c = 0; c < 8;c++)
	{
		al_draw_text(font,al_map_rgb(200,100,55),430,50+30*c,ALLEGRO_ALIGN_CENTER,scores[c].name);
	}
	for(int j = 0; j < 8;j++)
	{
		al_draw_textf(font,al_map_rgb(200,100,55),860,50+30*j,ALLEGRO_ALIGN_CENTER,"%i",scores[j].score);
	}
}